package edu.hawaii.duedates;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

/**
 * This will test the DueDates class.
 * 
 * @author Ronn Reeves and Robin E. Raqueno
 *
 */
public class TestDueDates {

  /** The library used for testing. */
  private static final String library = "-uhm";
  
  /** The user id used for testing. */
  private static final String user = System.getenv("DUEDATES_TESTUSER1_ID");
  
  /** The password used for testing. */
  private static final String password = System.getenv("DUEDATES_TESTUSER1_LASTNAME");


  /**
   * Tests the constructor method.
   */
  @Test (expected = NoClassDefFoundError.class)
  public void testConstructor() {
    String[] args = new String[10];
    args[0] = library;
    args[1] = user;
    args[2] = password;
    args[3] = "-sort";
    args[4] = "duedate";
    args[5] = "-within";
    args[6] = "7";
    args[7] = "-verbose";
    args[8] = "-repository";
    args[9] = "libraries.xml";
    
    DueDates dd = new DueDates(args);

    assertEquals("Library creation failed.", 1, dd.libraryCount);
  } 
  
  
  /**
   * Tests the reportUserCredentialError method.
   */
  @Test 
  public void testReportXmlFileError() {
    String[] args = new String[10];
    args[0] = library;
    args[1] = user;
    args[2] = password;
    args[3] = "-sort";
    args[4] = "duedate";
    args[5] = "-within";
    args[6] = "7";
    args[7] = "-verbose";
    args[8] = "-repository";
    args[9] = "libraries.xsd";

    DueDates dd = new DueDates(args);
    dd.report(); 

    assertEquals("reportXmlFileError() failed.", dd.validRepository, Boolean.FALSE);
  }
  
  
  /**
   * Tests the reportUserCredentialError method.
   */
  @Test
  public void testReportUserCredentialError() {
    String[] args = new String[2];
    args[0] = "-verbose";
    args[1] = user;

    DueDates dd = new DueDates(args);
    
    assertEquals("reportUserCredentialError() failed.", dd.libraryCount, 0);
  }
  
  /**
   * Tests toString method.
   */
  @Test
  public void testToString() {
    String[] args = new String[0];

    DueDates dd = new DueDates(args);
    
    assertEquals("toString() failed.", dd.toString(), DueDates.usageMessage);
  }  

  
  /**
   * Tests the main method.
   */
  @Test
  public void testMain() {
    String[] args = new String[0];
    DueDates.main(args);
    assertEquals("testMain failed.", "edu.hawaii.duedates.library", DueDates.packagePath);
  }
}